<template>
  <div>
    <!--    搜索表单-->
    <div>
      <el-input style="width: 240px" placeholder="请输入图书名" v-model="params.bookName"></el-input>
      <el-input style="width: 240px; margin-left: 5px" placeholder="请输入借阅人" v-model="params.userName"></el-input>
      <el-input style="width: 240px; margin-left: 5px" placeholder="请输入书号" v-model="params.bookIsbn"></el-input>
      <el-button style="margin-left: 5px" type="primary" @click="load()">
        <i class="el-icon-search"></i> 搜索
      </el-button>
      <el-button style="margin-left: 5px" type="danger" @click="reset">
        <i class="el-icon-refresh"></i>重置
      </el-button>
    </div>
    <!--增删改查-->
    <div style="margin: 10px 0">
    </div>
    <!--表单内容-->
    <el-table :data="tableData" stripe row-key="id" default-expand-all>
      <el-table-column fixed
                       prop="id"
                       label="编号"
                       width="60">
      </el-table-column>
      <el-table-column prop="bookName" label="书名"></el-table-column>
      <el-table-column prop="cover" label="封面" width="100">
        <template v-slot="scope">
          <el-image :src="scope.row.cover" :preview-src-list="[scope.row.cover]"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="bookIsbn" label="书号"></el-table-column>
      <el-table-column prop="userId" label="用户ID" width="100"></el-table-column>
      <el-table-column prop="userName" label="用户名称" width="120"></el-table-column>
      <el-table-column prop="userPhone" label="用户联系方式"></el-table-column>
      <el-table-column prop="score" label="所需积分"></el-table-column>
      <el-table-column prop="createTime" label="借出时间"></el-table-column>
      <el-table-column prop="status" label="借出状态"></el-table-column>
      <el-table-column prop="days" label="借出天数"></el-table-column>
      <el-table-column prop="returnTime" label="还书时间"></el-table-column>


      <!--操作-->
      <el-table-column
          fixed="right"
          label="操作"
          width="200">

        <template v-slot="scope">
          <el-popconfirm
              class="ml-5"
              title="您确定删除这行信息吗？"
              @confirm="del(scope.row.id)"
          >
            <el-button slot="reference" type="danger" size="small">删除 <i class="el-icon-remove-outline"></i>
            </el-button>
          </el-popconfirm>

        </template>
      </el-table-column>


    </el-table>

    <!--    分页-->
    <div style="text-align: center; ">
      <el-pagination
          background
          :current-page="params.pageNum"
          :page-size="params.pageSize"
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total">
      </el-pagination>
    </div>




  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "returnBook",
  data() {

    return {
      books: [],
      total: 0,
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      form: {},
    }
  },

  created() {
    this.load();
  },


  methods: {

    load() {
      request.get('/returnBook/page', {
        params: this.params
      }).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      })
    },

    reset() {
      this.params = {
        pageNum: 1,
        pageSize: 10,
        bookName: '',
        bookIsbn: '',
        userName: '',

      }
      this.load()
    },

    handleCurrentChange(pageNum) {
      this.params.pageNum = pageNum
      this.load()
    },



    del(id) {
      request.delete('/returnBook/delete/' + id).then(res => {
        if (res.code === '200') {
          this.$message.success('删除成功')
          this.load()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
  }
}
</script>

<style scoped>

</style>